package com.wc.alorithm_blue_bridge._DFS.Q7942;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

/**
 * @Author congege
 * @Description 公约移动
 * https://www.lanqiao.cn/problems/7942/learning/?problem_list_id=25&page=1
 * @Date Created in 2023/12/19-23:42
 */
public class Main {
    static FastReader in = new FastReader();
    static int maxN = 1000 + 10;
    static int[][] map = new int[maxN][maxN];
    static int[][][] vis = new int[maxN][maxN][4];
    static int n, m;
    static boolean[][] visS = new boolean[maxN][maxN];
    static int[] positionX = new int[]{-1, 0, 1, 0};
    static int[] positionY = new int[]{0, 1, 0, -1};
    static int ans = 1;

    public static void main(String[] args) {
        n = in.nextInt();
        m = in.nextInt();

        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= m; j++) {
                map[i][j] = in.nextInt();
            }
        }
        int x = in.nextInt();
        int y = in.nextInt();
        dfs(x, y);
        int ans = 0;
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= m; j++) {
                for (int k = 0; k < 4; k++) {
                    if (vis[i][j][k] == 1) {
                        ans++;
                        break;
                    }
                }
            }
        }
        // 如果说他傍边没有，说明就全是0了，他总要有一个自己
        if (ans == 0) {
            ans = 1;
        }
        System.out.println(ans);
    }

    public static void dfs2(int x, int y) {
        visS[x][y] = true;
        for (int i = 0; i < 4; i++) {
            int nextX = x + positionX[i];
            int nextY = y + positionY[i];
            if (!isBorder(nextX, nextY) && !visS[nextX][nextY] && gcd(map[x][y], map[nextX][nextY]) > 1) {
                ans++;
                dfs2(nextX, nextY);
            }
        }
    }

    public static void dfs(int x, int y) {
        for (int i = 0; i < 4; i++) {
            dfs(x + positionX[i], y + positionY[i], map[x][y], (i + 2) % 4);
        }
    }

    public static void dfs(int x, int y, int num, int op) {
        if (isBorder(x, y) || vis[x][y][op] != 0) {
            return;
        }
        if (gcd(map[x][y], num) > 1) {
            vis[x][y][op] = 1;
            vis[x + positionX[op]][y + positionY[op]][(op + 2) % 4] = 1;
            dfs(x, y);
        } else {
            vis[x][y][op] = -1;
            vis[x + positionX[op]][y + positionY[op]][(op + 2) % 4] = -1;
        }
    }

    public static boolean isBorder(int x, int y) {
        return x < 1 || x > n || y < 1 || y > m;
    }

    public static int gcd(int a, int b) {
        if (a > b) {
            return gcd(b, a);
        }
        while (b % a > 0) {
            b = b % a;
            a = a + b;
            b = a - b;
            a = a - b;
        }

        return a;
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    public FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }
}
